﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Hospitals/Master/HospitalsMaster.Master" AutoEventWireup="true" CodeBehind="PurchaseOrderImport.aspx.cs" Inherits="HZ.DrugTrade.Web.Hospitals.Procurement.PurchaseOrderImport" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript" language="Javascript">

        function verify_data(form) {
            var isError = false;
            var errorMessage = "";

            var hash = new Object();
            var required = new Object();

            required['ProcureCatalogID'] = '中标序号';
            required['PurchaseCount'] = '采购数量';

            for (i = 0; i < form.length; i++) {
                if (form.elements[i].name.indexOf("column", 0) == 0) {
                    if (form.elements[i].value == "-1") {
                        continue;
                    }
                    if (hash[form.elements[i].value] == 1) {
                        // got same field more than once
                        isError = true;
                    }
                    hash[form.elements[i].value] = 1;
                }
            }

            if (isError == true) {
                alert("多个字段使用同样的字段名称");
                return false;
            }

            for (var field_name in required) {
                // contacts hack to bypass errors if full_name is set
                if (hash[field_name] != 1) {
                    isError = true;
                    errorMessage += "缺少必需的字段： " + required[field_name] + "。\n";
                }
            }

            if (isError == true) {
                alert(errorMessage);
                return false;
            }
            return true;
        }

        function hidediv(id) {
            if (this.document.getElementById(id).style.display == 'block') {
                this.document.getElementById(id).style.display = 'none';
            }
        }

        function showdiv(id) {
            if (this.document.getElementById(id).style.display == 'none') {
                this.document.getElementById(id).style.display = 'block';
            }
        }

        function ConfirmSubmit() {

            var isExcel = document.getElementById('excel').checked;
            //var isMdb = document.getElementById('access').checked;

            if (isExcel ) {

                var tbName = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtTableName');
                if (tbName.value.replace(/(^s*)|(s*$)/g, "") == "") {
                    alert('请输入数据表名称！');
                    tbName.focus();
                    return false;
                }
                else {

                    if (Page_ClientValidate('submit')) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
            }
            else {
                if (Page_ClientValidate('submit')) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }

        //检查是否可以继续导入
        function CheckResult(obj) {
            var checkResult = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_CheckResult');
            if (checkResult.value == "OK") {
                if (Page_ClientValidate('submit2')) {
                    obj.value = "导入中...请稍后."
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                alert('数据检查失败，无法继续导入');
                return false;
            }
        }

        function initbName() { 
        
            var isExcel = document.getElementById('excel').checked;
            //var isMdb = document.getElementById('access').checked;

            if (isExcel ) {
                showdiv('tbName');
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" DisplaySideBar="False"
        Width="100%" OnFinishButtonClick="Wizard1_FinishButtonClick" >
        <WizardSteps>
            <asp:WizardStep ID="step1" runat="server" Title="Step 1" StepType="Auto">
                <div id="tabnav">
                    <ul>
                        <li class="active"><a href="javascript:void(0);">导入采购单向导</a></li>
                    </ul>
                </div>
                <div id="tabcontent">
                    <br />
                    &nbsp;&nbsp;请选择一种导入文件的类型:&nbsp;
                    <ul style="list-style-type: decimal">
                        <li>
                            <input id="csv" name="importType" value="csv" checked="checked" onclick="hidediv('tbName')"
                                type="radio" />逗号分隔的文件(.csv) </li>
                        <li>
                            <input id="excel" name="importType" value="excel"  onclick="showdiv('tbName')" type="radio" />微软Excel文件(.xls)
                        </li>
                        
                    </ul>
                    <table class="querylist">
                        <tr>
                            <td valign="top" width="80px" style="padding-top:6px;">
                                <asp:Label ID="Label2" runat="server" Text="请选择文件：" Font-Bold="True"></asp:Label>
                            </td>
                            <td valign="top" width="310px" align="left">
                                <asp:FileUpload ID="FileUpload1" runat="server" Width="300px" />
                                <br />
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="文件类型必须为(.csv | .xls)"
                                    ControlToValidate="FileUpload1" 
                                    ValidationExpression="^.*?\.(csv|xls)$" Display="Dynamic"
                                    ValidationGroup="submit"></asp:RegularExpressionValidator>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1"
                                    ErrorMessage="文件类型必须为(.csv | .xls)" Display="Dynamic" 
                                    ValidationGroup="submit"></asp:RequiredFieldValidator>
                            </td>
                            <td valign="top">
                                <div id="tbName" style="display: none">
                                    <asp:Label ID="Label3" runat="server" Text="数据表名：" Font-Bold="True"></asp:Label>
                                    <asp:TextBox ID="txtTableName" runat="server" Width="80px"></asp:TextBox> （如：Sheet1）
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="listip">
                    <ul>
                        <li>第一步:<span> 选择需要导入的文件！</span></li>
                    </ul>
                </div>
                <script type="text/javascript" language="javascript">
                    initbName();
                </script>
            </asp:WizardStep>
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 2">
                <input id="hdnTempFile" runat="server" type="hidden"></input>
                <input runat="server" id="hdnHasHeader" type="hidden"></input>
                <div id="tabnav">
                    <ul>
                        <li class="active"><a href="javascript:void(0);">导入采购单向导</a></li>
                    </ul>
                </div>
                <div id="tabcontent">
                    <br />
                    &nbsp;在下面的列表中，选择导入文件中包含的字段，完成后点击 执行导入：&nbsp;
                    <br />
                    <br />
                    <asp:Repeater runat="server" ID="rptRelation">
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                        <HeaderTemplate>
                            <table class="importlist">
                                <tr>
                                    <th>
                                        系统字段
                                    </th>
                                    <th>
                                        标题行
                                    </th>
                                    <th>
                                        行1
                                    </th>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td style="width: 200px">
                                    <select name="column<%# Container.ItemIndex %>">
                                        <option value="-1">-- 不对应这个字段 --</option>
                                        <option class="required" value="ProcureCatalogID">中标序号*</option>
                                        <option class="required" value="PurchaseCount">采购数量*</option>
                                                                                
                                    </select>
                                </td>
                                <td>
                                    <%# Eval("标题行") %>
                                </td>
                                <td>
                                    <%# Eval("行1")%>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
                <div class="listip">
                    <ul>
                        <li>第二步:<span> 对应数据库字段，校验数据</span></li>
                    </ul>
                </div>
            </asp:WizardStep>
            <asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3">
            <input id="CheckResult" runat="server" type="hidden"/></input>
                <div id="tabnav">
                    <ul>
                        <li class="active"><a href="javascript:void(0);">导入采购单向导</a></li>
                    </ul>
                </div>
                <div id="tabcontent">
                    <br />
                     &nbsp;&nbsp;数据校验结果:&nbsp;
                    <ul style="list-style-type: decimal">
                         <asp:Literal ID="ltlResult" runat="server"></asp:Literal>
                    </ul>
                    <table class="importlist" runat="server" id="tbOrder" visible="false">
                        <tr>
                            <th align="right" style="width:100px">
                                <asp:Label ID="lblPurchaseOrderName" runat="server" Text="采购单名称："></asp:Label>
                            </th>
                            <td align="left" colspan="3">
                                <asp:TextBox ID="txtPurchaseOrderName" runat="server" Width="260px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <th align="right">
                                <asp:Label ID="lblPurchaseOrderTime" runat="server" Text="建单时间："></asp:Label>
                            </th>
                            <td align="left"  style=" width:80px">
                                <asp:TextBox ID="txtPurchaseOrderTimeFrom" runat="server" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" ></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPurchaseOrderTimeFrom"
                                    ErrorMessage="*" Display="Dynamic" 
                                    ValidationGroup="submit2"></asp:RequiredFieldValidator>
                            </td>
                            <th runat="server" align="right" style=" width:100px">
                                要求到货时间：</th>
                            <td runat="server" align="left">
                                <asp:TextBox ID="txtPurchaseOrderTimeTo" runat="server" 
                                    onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtPurchaseOrderTimeTo"
                                    ErrorMessage="*" Display="Dynamic" 
                                    ValidationGroup="submit2"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <th align="right">
                                <asp:Label ID="lblRemarks" runat="server" Text="备  注："></asp:Label>
                            </th>
                            <td align="left" colspan="3"> 
                                <asp:TextBox ID="txtRemarks" runat="server" TextMode="MultiLine" Rows="5" Columns="70"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                    
                </div>
                <div class="listip">
                    <ul>
                        <li>第三步:<span> 显示数据校验结果，确认导入！</span></li>
                    </ul>
                </div>
            </asp:WizardStep>
        </WizardSteps>
        <StartNavigationTemplate>
            <br />
            <hz:HzButton ID="StartNextButton" runat="server" CommandName="MoveNext" Text="下一步"
                ValidationGroup="submit" OnClientClick="return ConfirmSubmit();" 
                onclick="StartNextButton_Click"  />
        </StartNavigationTemplate>
        <FinishNavigationTemplate>
            <br />
            <asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
                Text="上一步" onclick="FinishPreviousButton_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete" Text="执行导入" ValidationGroup="submit2"
               OnClientClick="return CheckResult(this);"  />
        </FinishNavigationTemplate>
        <StepNavigationTemplate>
            <br />
            <asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious"
                Text="上一步" onclick="StepPreviousButton_Click" />
            <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" 
              OnClientClick="return verify_data(aspnetForm);"   Text="数据校验" onclick="StepNextButton_Click" />
        </StepNavigationTemplate>
       
        
    </asp:Wizard>
    
</asp:Content>
